package com.sunlgggg.view;


import com.sunlgggg.view.component.*;
import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.*;


public class MainFrame extends JFrame {

    public static String currentAccount;

    private static final long serialVersionUID = 1L;
    private int WINDOW_WIDTH = 1100;
    private int WINDOW_HEIGHT = 600;

    private JPanel navigatorPanel;
    private MangerPanel mangerPanel;
    private SelectPanel selectPanel;
    private ResetPanel resetPanel;

    private JLabel managerLabel;
    private JLabel selectLabel;
    private JLabel resetLabel;

    public MainFrame(String currentAccount) {


        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());  //设置界面样式
            UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
            UIManager.getCrossPlatformLookAndFeelClassName();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }

        this.currentAccount = currentAccount;
        this.setTitle("班级信息管理");
        this.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
        this.setLayout(new BorderLayout(10, 10));
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);


        setJMenuBar(new com.sunlgggg.view.component.MenuBar());

        buildNavigatorPanel();

        buildMainPanel();

        this.add(navigatorPanel, BorderLayout.WEST);
        this.add(selectPanel, BorderLayout.CENTER);
        this.add(mangerPanel, BorderLayout.CENTER);
        this.setVisible(true);
    }


    public void buildNavigatorPanel() {
        navigatorPanel = new JPanel();

        Border insideBorder = BorderFactory.createEmptyBorder(20, 0, 0, 0);
        Border outsideBorder = BorderFactory.createLoweredBevelBorder();
        navigatorPanel.setBorder(BorderFactory.createCompoundBorder(outsideBorder, insideBorder));

        navigatorPanel.setPreferredSize(new Dimension(100, 500));

        managerLabel = new JLabel("处理记录", SwingConstants.CENTER);
        managerLabel.setPreferredSize(new Dimension(100, 30));
        managerLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));

        selectLabel = new JLabel("查询记录", SwingConstants.CENTER);
        selectLabel.setPreferredSize(new Dimension(100, 30));
        selectLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));


        resetLabel = new JLabel("重置密码", SwingConstants.CENTER);
        resetLabel.setPreferredSize(new Dimension(100, 30));
        resetLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));


        navigatorPanel.add(managerLabel);
        navigatorPanel.add(selectLabel);
        navigatorPanel.add(resetLabel);

        managerLabel.addMouseListener(new LabelClick());
        selectLabel.addMouseListener(new LabelClick());
        resetLabel.addMouseListener(new LabelClick());
    }

    public void buildMainPanel() {
        managerLabel.setForeground(Color.red);
        mangerPanel = new MangerPanel();
        mangerPanel.setVisible(true);
        selectPanel = new SelectPanel();
        selectPanel.setVisible(false);
        resetPanel = new ResetPanel();
        resetPanel.setVisible(false);

    }

    public class LabelClick extends MouseAdapter {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getSource() == managerLabel) {
                managerLabel.setForeground(Color.red);
                resetLabel.setForeground(Color.black);
                selectLabel.setForeground(Color.black);
                mangerPanel.setVisible(true);
                selectPanel.setVisible(false);
                resetPanel.setVisible(false);
                MainFrame.this.add(mangerPanel, BorderLayout.CENTER);

            } else if (e.getSource() == selectLabel) {
                managerLabel.setForeground(Color.black);
                resetLabel.setForeground(Color.black);
                selectLabel.setForeground(Color.red);
                mangerPanel.setVisible(false);
                selectPanel.setVisible(true);
                resetPanel.setVisible(false);
                MainFrame.this.add(selectPanel, BorderLayout.CENTER);
            } else if (e.getSource() == resetLabel) {
                managerLabel.setForeground(Color.black);
                resetLabel.setForeground(Color.red);
                selectLabel.setForeground(Color.black);
                mangerPanel.setVisible(false);
                selectPanel.setVisible(false);
                resetPanel.setVisible(true);
                MainFrame.this.add(resetPanel, BorderLayout.CENTER);
            }
        }
    }

    public static void main(String[] args) {
        new MainFrame("admin");
    }
}
